Ext.define('Triends.view.PostingLocation', {
 	extend: 'Ext.form.Panel',
 	xtype: 'postinglocation',
 	id: 'postinglocation',
 	config: {
 		fullscreen: true,
 		showAnimation: 'slideIn',
 		listeners: {
 			deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
	 					Ext.getCmp('continent').reset();
	 					Ext.getCmp('nation').reset();
	 					Ext.getCmp('locationtitlefield').reset();
	 					Ext.getCmp('locationcontentfield').reset();
				}
 		},
 		items: [
 		{
 			xtype: 'locationfield1'
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Title',
 			items: [{
 				xtype: 'textfield',
 				name: 'title',
 				style: 'border:3px inset',
 				id: 'locationtitlefield'
 			}]
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Content',
 			items: [{
 				xtype: 'textareafield',
 				name: 'content',
 				height: 200,
 				maxRows: 7,
 				style: 'border:3px inset',
 				id: 'locationcontentfield'
 			}]
 		},
 		{
 			xtype: 'panel',
 			layout: 'hbox',
 			items:[{
 				xtype: 'button',
	 			text: '등록',
	 			style: {'left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 		width: '100%',
	 			handler: function(){
	 				var userid = Ext.getStore('UserStore').getAt(0).data.ID;
	 				var username = Ext.getStore('UserStore').getAt(0).data.Name;
	 				
	 				var titlefield = Ext.getCmp('locationtitlefield');
	 				var contentfield = Ext.getCmp('locationcontentfield');
	 				var continent = Ext.getCmp('continent');
	 				var nation = Ext.getCmp('nation');
	 				
	 				if(continent.getValue() == ""){
	 					Ext.Msg.alert("","대륙을 선택하세요");
	 					return;
	 				}
	 				if(nation.getValue() == ""){
	 					Ext.Msg.alert("","국가를 선택하세요");
	 					return;
	 				}
	 				if(titlefield.getValue() == ""){
	 					Ext.Msg.alert("","Title을 입력하세요");
	 					return;
	 				}
	 				if(contentfield.getValue() == ""){
	 					Ext.Msg.alert("","Content를 입력하세요");
	 					return;
	 				}
	 				
	 				Ext.Ajax.request({
	 					url: 'http://itscreater.cafe24.com/Triends/Posting.jsp',
	 					params: {
	 						id: userid,
	 						name: username,
	 						title: titlefield.getValue(), 
	 						content: contentfield.getValue(),
	 						continent: continent.getValue(), 
	 						nation: nation.getValue()
	 					},
	 					success: function(response){
	 							var postLocationStore = Ext.getStore("postlocationstore");
	 									postLocationStore.removeAll();
				 						postLocationStore.setProxy({
											type: "jsonp",
											url: 'http://itscreater.cafe24.com/Triends/PostLocationList.jsp',
											extraParams: {continent: continent.getValue(),
														  nation: nation.getValue()},
											callbackkey: 'callback',
											pageParam: 'pages',
											limitParam: 'rpp',
											reader: {
												type: "json",
												rootProperty: "results",
												totalProperty: "total"
											}
										})
										postLocationStore.loadPage(1);
	 						Ext.Msg.show({
	 							message: '글이 등록되었습니다',
	 							buttons:[{text: '확인', itemId: 'ok',ui: 'action'}],
	 							fn: function(buttonId){
	 								if(buttonId == 'ok'){
	 								
										Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            								url: 'mainpage'
        								}));
	 								}
	 							}
	 						});
							localStorage.removeItem(continent);
							localStorage.removeItem(nation);
							localStorage.setItem("continent", continent.getValue());
							localStorage.setItem("nation", nation.getValue());
	 						continent.reset();
	 						nation.reset();
	 						titlefield.reset();
	 						contentfield.reset();
	 						
	 						
	        			}
	 				});
 				}
 			}]
 		},
 		{
 				
 		}]
 	}
});